package com.ruoyi.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.SupplierInfo;
import com.ruoyi.service.ISupplierInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 供应商
 */
@RestController
@RequestMapping("/webshop/supplierInfo")
public class SupplierInfoController extends BaseController {
@Autowired
private ISupplierInfoService supplierInfoService;

// 全查
@GetMapping("/list")
public List<SupplierInfo> list(){
    List<SupplierInfo> list = supplierInfoService.list();
    return list;
}
@GetMapping("/listForPage")
public TableDataInfo listForPage(SupplierInfo supplierInfo) {
    System.out.println("supplierInfo = " + supplierInfo);
    startPage();
    List<SupplierInfo> list = supplierInfoService.listForPage(supplierInfo);

    return getDataTable(list);
}
// 根据id查一条
@GetMapping("/{id}")
public AjaxResult getInfo(@PathVariable Long id){
    System.out.println("id = " + id);
    SupplierInfo supplierInfo = supplierInfoService.getById(id);
    return success(supplierInfo);
}
// 添加
@PostMapping()
public AjaxResult add(@RequestBody SupplierInfo supplierInfo){
    System.out.println("supplierInfo = " + supplierInfo);
    int add = supplierInfoService.save(supplierInfo);
    return toAjax(add);
}
// 修改
@PutMapping()
public AjaxResult edit(@RequestBody SupplierInfo supplierInfo){
    System.out.println("supplierInfo = " + supplierInfo);
    int edit = supplierInfoService.updateById(supplierInfo);
    return toAjax(edit);
}
// 根据ids删除多条
@DeleteMapping("/{ids}")
public AjaxResult deleteMany(@PathVariable Long[] ids){
    System.out.println("ids = " + Arrays.toString(ids));
    int delete = supplierInfoService.removeByIds(ids);
    return toAjax(delete);
}
}
